package cn.org.zx.notebook.blh;

import java.util.HashMap;
import java.util.Map;

import cn.org.zx.common.commutils.StringUtils;
import cn.org.zx.common.dao.DBAccess;

public class NoteBookBlh {		
	//密码修改初始化
	public Map<String, Object> getNoteBookQueryList(Map<String, Object> mapData){
		Map<String, Object> mapReturn = new HashMap<String, Object>();
		
		String strSql = "";		

		strSql="select nb_id,nb_date as nbdate,nb_content,nb_state,nb_createuserid,SYSDATE() as cdate from tb_notebook";
		strSql+=" where DATE_FORMAT(nb_date,'yyyy-mm-dd')>=DATE_FORMAT(SYSDATE(),'yyyy-mm-dd') and nb_state='0'";
		strSql+=" order by nb_date";
		//System.out.println("strSql="+strSql);
		mapReturn.put("notebookdatalist", DBAccess.query(strSql));
		
		return mapReturn;
	}
	
	//记事本新增保存
	public Map<String, Object> getNoteBookCreateSave(Map<String, Object> mapData,String strUserID){
		Map<String, Object> mapReturn = new HashMap<String, Object>();
		String strSql = "";

		String strnbtitle = StringUtils.toString(mapData.get("notebooktitlec"));
		String strnbdate = StringUtils.toString(mapData.get("notebookdatec"));
		String strntcontent = StringUtils.toString(mapData.get("notebookcontentc"));
		
		if(!strUserID.equals("")){
			strSql = "insert into tb_notebook(nb_id,nb_title,nb_date,nb_content,nb_state,nb_createuserid,nb_createdate)values(";
			strSql+="ssnotebookid.nextval,'"+strnbtitle+"','"+strnbdate+"','"+strntcontent+"','0',"+strUserID+",SYSDATE())";
			mapReturn.put("mapReturn", DBAccess.update(strSql)==true?"success":"fail");
		}
		
		return mapReturn;
	}
	
	//记事本记录查看
	public Map<String, Object> getNoteBookView(Map<String, Object> mapData){
		Map<String, Object> mapReturn = new HashMap<String, Object>();		
		String strSql = "";
		
		String strnbtid = StringUtils.toString(mapData.get("nbid"));
				
		if(!strnbtid.equals("")){			
			strSql="select * from tb_notebook where nb_id="+strnbtid+"";			
			//System.out.println("strSql="+strSql);
			mapReturn.putAll(DBAccess.queryOneRow(strSql));
		}
		
		return mapReturn;
	}
	
	//记事本记录删除 
	public Map<String, Object> getNoteBookDelete(Map<String, Object> mapData,String strUserID){
		Map<String, Object> mapReturn = new HashMap<String, Object>();
		String strSql = "";
		
		String strnbid = StringUtils.toString(mapData.get("nbid"));
				
		if(!strnbid.equals("") && !strUserID.equals("")){
			strSql = "update tb_notebook set nb_state='1' where nb_id="+strnbid+" and nb_createuserid="+strUserID+" and nb_state='0'";
			mapReturn.put("mapReturn", DBAccess.update(strSql)==true?"success":"fail");
		}
		
		return mapReturn;
	}
}
